package com.borderbears.backend.actions;

import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractAction;

import com.borderbears.backend.BCBackendApp;
import com.borderbears.backend.connection.Connection;
import com.borderbears.backend.connection.ConnectionManager;
import com.borderbears.backend.gui.ConfirmDialog;
import com.borderbears.backend.gui.ConnectionEditorForm;

public class EditConnectionAction extends AbstractAction {

	private final Connection connection;

	public EditConnectionAction(final String name, final Connection c) {
		super(name);
		connection = c;
	}


	public void actionPerformed(final ActionEvent e) {
		final ConfirmDialog dialog = new ConfirmDialog(BCBackendApp
				.getApplication().getMainFrame(), "Add Connection",
				ModalityType.APPLICATION_MODAL);
		final ConnectionEditorForm panel = new ConnectionEditorForm();
		panel.setConnection(connection);
		dialog.setContent(panel);
		// dialog.setContent(panel);
		dialog.addActonListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				ConnectionManager.getInstance().addConnection(panel.getConnection());
			}
		});
		dialog.setVisible(true);
	}

}
